package com.sean.reverse.util;

import lombok.Data;

/**
 * des:
 *
 * @author HuZhenSha
 * @date 2021/3/5 15:35
 */


@Data
public class Result<T> {

    private int code;
    private String message;
    private T data;


    private Result() {
    }

    public static<T> Result<T> success(){
        Result<T> result= new Result<>();
        result.code = ResultCode.SUCCESS.getCode();
        result.message = ResultCode.SUCCESS.getMessage();
        return result;
    }

    public static<T> Result<T> success(T t){
        Result<T> result= new Result<>();
        result.code = ResultCode.SUCCESS.getCode();
        result.message = ResultCode.SUCCESS.getMessage();
        result.data = t;
        return result;
    }

    public static<T> Result error(ResultCode resultEnum){
        Result<T> result= new Result<>();
        result.code = resultEnum.getCode();
        result.message = resultEnum.getMessage();
        result.data = null;
        return result;
    }

    public static<T> Result<T> error(String msg){
        Result<T> result= new Result<>();
        result.code = ResultCode.FAILURE.getCode();
        result.message = msg;
        result.data = null;
        return result;
    }

}
